package com.ohc.leetcode.数组;

import java.util.Arrays;

/**
 * 2022年5月17日09:12:26
 */
public class 二分查找704 {

    public static int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int mid = 0;
        while (left < right) {
            mid = (right + left) / 2;
            if (nums[mid] < target) {
                left = mid + 1;
            } else if (nums[mid] > target) {
                right = mid - 1;
            } else {
                return mid ;
            }
        }
        return -1;
    }


    public static void main(String[] args) {
        int[] arr = {-1,0,3,5,9,12};
        int i = search(arr, 2);
        System.out.println(i);
    }
}
